#ifndef __GAME_H__
#define __GAME_H__

/**
 * 存放所有字模数据
 */
unsigned char code START_PIC[] = {

    0x00,0x00,0x3E,0x22,0x22,0xBE,0x62,0x22,
    0x22,0x3E,0x22,0x22,0x3E,0x00,0x00,0x00,
    0x10,0x0C,0x14,0xD4,0x54,0x54,0x55,0x56,
    0x54,0x54,0x54,0xD4,0x14,0x14,0x0C,0x00,
    0x00,0x82,0x82,0xBA,0xAA,0xAA,0xAA,0xAB,
    0xAA,0xAA,0xAA,0xBA,0x82,0x82,0x80,0x00,
    0x80,0x84,0x84,0x42,0x45,0x49,0x31,0x21,
    0x11,0x09,0x05,0x03,0x00,0x00,0x00,0x00,
    0x00,0x00,0xFC,0x55,0x55,0x55,0x55,0x7D,
    0x55,0x55,0x55,0x55,0xFC,0x00,0x00,0x00,
    0x02,0x01,0xA0,0xAA,0xAA,0x56,0x56,0xAA,
    0xF2,0x12,0x2A,0x22,0x40,0x42,0x01,0x00,
    };//罗富豪

// 数字字模，4x8
unsigned char code NUM_CHARS[] = {
    0x7F, 0x41, 0x41, 0x7F, // 0字模
    0x00, 0x00, 0x00, 0x7F, // 1字模
    0x79, 0x49, 0x49, 0x4F, // 2字模
    0x49, 0x49, 0x49, 0x7F, // 3字模
    0x0F, 0x08, 0x08, 0x7F, // 4字模
    0x4F, 0x49, 0x49, 0x79, // 5字模
    0x7F, 0x49, 0x49, 0x79, // 6字模
    0x01, 0x01, 0x01, 0x7F, // 7字模
    0x7F, 0x49, 0x49, 0x7F, // 8字模
    0x4F, 0x49, 0x49, 0x7F, // 9字模
};

/**
 * 左右箭头，4x8
 */
unsigned char code LEFT_ARROW[] = {0x08, 0x1c, 0x3e, 0x7f};
unsigned char code RIGHT_ARROW[] = {0x7f, 0x3e, 0x1c, 0x08};
/**
 * 上下箭头
 */
unsigned char code UP_ARROW[] ={0x10,0x18,0x1C,0x1E,0x1C,0x18,0x10,0x00};
unsigned char code DOWN_ARROW[] ={0x01,0x03,0x07,0x0F,0x07,0x03,0x01,0x00};
/**
 * SPEED 字模，4x8
 */
unsigned char code SPEED_CHARS[] = {
    0x46, 0x49, 0x49, 0x31,  // S
    0x00,                    // 空一列
    0x7F, 0x09, 0x09, 0x06,  // P
    0x00,                    // 空一列
    0x7F, 0x49, 0x49, 0x49,  // E
    0x00,                    // 空一列
    0x7F, 0x49, 0x49, 0x49,  // E
    0x00,                    // 空一列
    0x7F, 0x41, 0x41, 0x3E}; // D




unsigned int idata GAME_ZONE[19];

#define GAME_FRAME_TOTAL 10
unsigned char game_frame_count = 0;

struct
{
    // TETRIS_SHAPES二维数组的两个维度
    unsigned char shape_type; // 方块的形状类型 0-6
    unsigned char shape_pos;  // 方块的方位 0-3
    // 位于游戏区域的坐标
    unsigned char x;         // 水平方位 0~9
    unsigned char y;         // 竖直的方位  0~15
    unsigned int shape;      // 形状数据 TETRIS_SHAPES中的一条数据
    unsigned char next_type; // 下一个方块的类型
    unsigned char next_pos;  // 下一个方块的方位
} game_shape;

sbit BTN_START = P1 ^ 0;
sbit BTN_PAUSE = P1 ^ 1;
sbit BTN_UP = P1 ^ 2;
sbit BTN_DOWN = P1 ^ 3;
sbit BTN_LEFT = P1 ^ 4;
sbit BTN_RIGHT = P1 ^ 5;

#define PRESSED_NONE 0
#define PRESSED_START 1
#define PRESSED_PAUSE 2
#define PRESSED_UP 3
#define PRESSED_DOWN 4
#define PRESSED_LEFT 5
#define PRESSED_RIGHT 6

#define STATUS_START 0
#define STATUS_SPEED_SELECT 1
#define STATUS_PALYING 2
#define STATUS_GAME_OVER 3
#define STATUS_PAUSE 4
unsigned char game_status = STATUS_START;
unsigned char game_speed = 0;
unsigned int game_score = 0;
unsigned int game_eliminated_lines = 0;

#define BTN_COUNT_DOWN 50
// 做持续按下的计数
unsigned int game_button_pressed_count = 0;
// 上一次按下的按键
unsigned int game_button_last_pressed = PRESSED_NONE;

#define BUTTON_ACCELERATION_MAX 4
// 连续按下按键，等待之后速度加速
unsigned char game_button_acceleration = 1;

#endif